package controller

import (
	"strconv"
	"testing"

	"github.com/aquasecurity/trivy-operator/pkg/kube"
)

func BenchmarkCompareReports(b *testing.B) {
	// Setup test cases with different sizes
	testCases := []struct {
		name   string
		actual map[string]bool
		images kube.ContainerImages
	}{
		{
			name:   "Small - 5 containers",
			actual: map[string]bool{"container1": true, "container2": true, "container3": true, "container4": true, "container5": true},
			images: kube.ContainerImages{"container1": "image1", "container2": "image2", "container3": "image3", "container4": "image4", "container5": "image5"},
		},
		{
			name:   "Medium - 50 containers",
			actual: make(map[string]bool),
			images: make(kube.ContainerImages),
		},
		{
			name:   "Large - 500 containers",
			actual: make(map[string]bool),
			images: make(kube.ContainerImages),
		},
		{
			name:   "Mismatch - different sizes",
			actual: map[string]bool{"container1": true, "container2": true},
			images: kube.ContainerImages{"container1": "image1", "container2": "image2", "container3": "image3"},
		},
		{
			name:   "Mismatch - same size but different keys",
			actual: map[string]bool{"container1": true, "container2": true, "container4": true},
			images: kube.ContainerImages{"container1": "image1", "container2": "image2", "container3": "image3"},
		},
	}

	// Fill medium and large test cases
	for i := 1; i <= 50; i++ {
		containerName := "container" + strconv.Itoa(i)
		testCases[1].actual[containerName] = true
		testCases[1].images[containerName] = "image" + strconv.Itoa(i)
	}

	for i := 1; i <= 500; i++ {
		containerName := "container" + strconv.Itoa(i)
		testCases[2].actual[containerName] = true
		testCases[2].images[containerName] = "image" + strconv.Itoa(i)
	}

	// Run benchmarks
	for _, tc := range testCases {
		b.Run(tc.name, func(b *testing.B) {
			for i := 0; i < b.N; i++ {
				compareReports(tc.actual, tc.images)
			}
		})
	}
}
